const jwt = require('jsonwebtoken');
const config = require('../config/config');

// 生成访问令牌
exports.generateAccessToken = (userId) => {
    return jwt.sign({ userId }, config.jwtSecret, {
        expiresIn: config.jwtExpiresIn
    });
};

// 生成刷新令牌
exports.generateRefreshToken = (userId) => {
    return jwt.sign({ userId }, config.jwtSecret, {
        expiresIn: config.refreshTokenExpiresIn
    });
};

// 验证令牌
exports.verifyToken = (token) => {
    try {
        return jwt.verify(token, config.jwtSecret);
    } catch (error) {
        return null;
    }
}; 